import React, { useEffect, useRef } from 'react';

import './index.css';

function Test() {
  const divRef = useRef<HTMLInputElement>(null)
  console.log('组件渲染了'); // 只会渲染一次
  function changeInput (e) {
    // 非受控
    console.log(e.target.value, 'e');
  }

  useEffect(() => {
    setTimeout(() => {
        // 通过ref拿到.value的值
        console.log(divRef.current?.value, 'divRef.current');
    }, 2000)
  }, [])
  return <div>
    <input ref={divRef} type="text" defaultValue={'guang'} onChange={changeInput} />
  </div>
}

function App() {

  return (
    <div className="App">
      <Test />
    </div>
  );
}

export default App;
